<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="项羽大大, php, 艹代码" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="敲敲代码看看电视刷刷微博">
<meta property="og:type" content="website">
<meta property="og:title" content="项羽大大的博客">
<meta property="og:url" content="http://blog.caocode.com/index.html">
<meta property="og:site_name" content="项羽大大的博客">
<meta property="og:description" content="敲敲代码看看电视刷刷微博">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="项羽大大的博客">
<meta name="twitter:description" content="敲敲代码看看电视刷刷微博">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://blog.caocode.com/"/>

  <title> 项羽大大的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?65de5000df47cefa2d258fc5c482a218";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">项羽大大的博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">一个逗比的Blog</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2016/10/14/aira2/" itemprop="url">
                  aira2 - mac百度网盘下载
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-10-14T10:40:23+08:00" content="2016-10-14">
              2016-10-14
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/10/14/aira2/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/10/14/aira2/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><code>使用mac的朋友如果想从百度网盘下载东西肯定都苦恼过，当初我的办法就是开个虚拟机然后去下，但想下东西还每次开虚拟机还是很不爽的。今天给大家推荐个工具 *aria2*</code></p>
<h3 id="aria2是什么？"><a href="#aria2是什么？" class="headerlink" title="aria2是什么？"></a>aria2是什么？</h3><p>aria2 是一款支持多种协议的轻量级命令行下载工具。有以下特性：</p>
<ul>
<li><strong>多线程连线：</strong>aria2 会自动从多个线程下载文件，并充分利用你的带宽；</li>
<li><strong>轻量：</strong>运行时不会占用过多资源，根据官方介绍，内存占用通常在 4MB~9MB，使用 BitTorrent 协议，下行速度 2.8MB/s 时 CPU 占用率约 6%；</li>
<li><strong>全功能 BitTorrent 客户端</strong>；</li>
<li><strong>支持 RPC 界面远程控制</strong>（下文重点介绍）。</li>
</ul>
<h3 id="开始吧"><a href="#开始吧" class="headerlink" title="开始吧"></a>开始吧</h3><p>1.dmg下载传送门(这个安装好后会给你配置好环境) <a href="https://github.com/yangshun1029/aria2gui/releases" target="_blank" rel="external">https://github.com/yangshun1029/aria2gui/releases</a> （下载页面中的 dmg 包）</p>
<p>2.还需要下载一个浏览器插件这下源码如谷歌下载后在扩展点开发者模式然后导入插件 <a href="https://github.com/acgotaku/BaiduExporter" target="_blank" rel="external">https://github.com/acgotaku/BaiduExporter</a></p>
<p><img src="http://7xnghc.com1.z0.glb.clouddn.com/aria2_1.png" alt="浏览器插件"></p>
<p><strong>解压压缩包然后打开谷歌扩展勾选开发者导入插件</strong></p>
<p><img src="http://7xnghc.com1.z0.glb.clouddn.com/aria22.png" alt="安装谷歌插件"></p>
<p>最后你还需要一个配置文件我把我的打包好了(<a href="https://pan.baidu.com/s/1qXDo4c0" target="_blank" rel="external">https://pan.baidu.com/s/1qXDo4c0</a>)</p>
<p>需要把里面的<code>aria2c.conf</code>配置文件的下载目录改成你自己的地址</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#文件保存路径, 默认为当前启动位置 xiangyu 是我的用户名目录你自己定义</span><br><span class="line">dir=/Users/xiangyu/Downloads/baiduyun/</span><br></pre></td></tr></table></figure>
<p>然后准备工作就好了。 </p>
<p>现在我们需要打开终端进入配置文件的目录</p>
<p>然后输入 <code>sh start.sh</code>启用然后我们就可以愉快的下载了</p>
<p><img src="http://7xnghc.com1.z0.glb.clouddn.com/aria2_4.png" alt=""></p>
<p><code>看到上面界面就说明正常了然后去下载的时候这里会有进度</code></p>
<p>说了这么说还没终于要到下载的时候了</p>
<p>打开自己的网盘找到要下载的文件找到<code>导出下载</code>然后点击<code>ARIA2 PRC</code></p>
<p><img src="http://7xnghc.com1.z0.glb.clouddn.com/aria2_3.png" alt="下载"></p>
<p>注：我也是刚玩，马上就发出来了，知道的也不多。如果有什么不好的欢迎大家补充</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2016/08/30/asynchronous/" itemprop="url">
                  PHP实现异步调用方法研究
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-30T19:02:00+08:00" content="2016-08-30">
              2016-08-30
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/08/30/asynchronous/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/08/30/asynchronous/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ul>
<li>问题：需要请求一个推送的结果，不需要知道他的返回结果，有时候接口会很慢造成自身业务时间太长</li>
<li>解决：鸟哥的<a href="http://www.laruence.com/2008/04/14/318.html" target="_blank" rel="external"><code>PHP实现异步调用方法研究</code></a></li>
</ul>
<p>浏览器和服务器之间是通过 HTTP 协议进行连接通讯的。这是一种基于请求和响应模型的协议。浏览器通过 URL 向服务器发起请求，Web 服务器接收到请求，执行一段程序，然后做出响应，发送相应的html代码给客户端。</p>
<p>这就有了一个问题，Web 服务器执行一段程序，可能几毫秒就完成，也可能几分钟都完不成。如果程序执行缓慢，用户可能没有耐心等下去，就关闭浏览器了。</p>
<p>而有的时候，我们更本不关心这些耗时的脚本的返回结果，但却还要等他执行完返回，才能继续下一步。<br>那么有没有什么办法，只是简单的触发调用这些耗时的脚本然后就继续下一步，让这些耗时的脚本在服务端慢慢执行？</p>
<p>经过试验，总结出来几种方法，和大家share：  </p>
<h4 id="ajax"><a href="#ajax" class="headerlink" title="ajax"></a><code>ajax</code></h4><p>最简单的办法，就是在返回给客户端的HTML代码中，嵌入AJAX调用，或者，嵌入一个img标签，src指向要执行的耗时脚本。<br>这种方法最简单，也最快。服务器端不用做任何的调用。<br>但是缺点是，一般来说Ajax都应该在onLoad以后触发，也就是说，用户点开页面后，就关闭，那就不会触发我们的后台脚本了。<br>而使用img标签的话，这种方式不能称为严格意义上的异步执行。用户浏览器会长时间等待php脚本的执行完成，也就是用户浏览器的状态栏一直显示还在load。<br>当然，还可以使用其他的类似原理的方法，比如script标签等等。</p>
<hr>
<h4 id="popen"><a href="#popen" class="headerlink" title="popen()"></a><code>popen()</code></h4><p>resource popen ( string command, string mode );<br>//打开一个指向进程的管道，该进程由派生给定的 command 命令执行而产生。打开一个指向进程的管道，该进程由派生给定的 command 命令执行而产生。</p>
<p>所以可以通过调用它，但忽略它的输出。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pclose(popen(&quot;/home/xinchen/backend.php &amp;&quot;, &apos;r&apos;));</span><br></pre></td></tr></table></figure>
<p>这个方法避免了第一个方法的缺点，并且也很快。但是问题是，这种方法不能通过HTTP协议请求另外的一个WebService，只能执行本地的脚本文件。并且只能单向打开，无法穿大量参数给被调用脚本。<br>并且如果，访问量很高的时候，会产生大量的进程。如果使用到了外部资源，还要自己考虑竞争。</p>
<hr>
<h4 id="使用CURL"><a href="#使用CURL" class="headerlink" title="使用CURL"></a><code>使用CURL</code></h4><p>这个方法，设置CUROPT_TIMEOUT为1（最小为1，郁闷）。也就是说，客户端至少必须等待1秒钟。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$ch = curl_init();</span><br><span class="line"> </span><br><span class="line">$curl_opt = array(CURLOPT_URL, &apos;http://www.example.com/backend.php&apos;,</span><br><span class="line">                            CURLOPT_RETURNTRANSFER, 1,</span><br><span class="line">                            CURLOPT_TIMEOUT, 1,);</span><br><span class="line"> </span><br><span class="line">curl_setopt_array($ch, $curl_opt);</span><br><span class="line"> </span><br><span class="line">curl_exec($ch);</span><br><span class="line"> </span><br><span class="line">curl_close($ch);</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="使用fsockopen"><a href="#使用fsockopen" class="headerlink" title="使用fsockopen"></a><code>使用fsockopen</code></h4><p>这个方法应该是最完美的，但是缺点是，你需要自己拼出HTTP的header部分。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$fp = fsockopen(&quot;www.example.com&quot;, 80, $errno, $errstr, 30);</span><br><span class="line">if (!$fp) &#123;</span><br><span class="line">    echo &quot;$errstr ($errno)&lt;br /&gt;\n&quot;;</span><br><span class="line">&#125; else &#123;</span><br><span class="line">    $out = &quot;GET /backend.php  / HTTP/1.1\r\n&quot;;</span><br><span class="line">    $out .= &quot;Host: www.example.com\r\n&quot;;</span><br><span class="line">    $out .= &quot;Connection: Close\r\n\r\n&quot;;</span><br><span class="line"> </span><br><span class="line">    fwrite($fp, $out);</span><br><span class="line">    /*忽略执行结果</span><br><span class="line">    while (!feof($fp)) &#123;</span><br><span class="line">        echo fgets($fp, 128);</span><br><span class="line">    &#125;*/</span><br><span class="line">    fclose($fp);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>所以，总体来看，最好用，最简单的还是第一种方法。<br>最完美的应该是最后一种，但是比较复杂</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2016/08/19/php-bug/" itemprop="url">
                  小记php的坑(一)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-19T17:14:24+08:00" content="2016-08-19">
              2016-08-19
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/08/19/php-bug/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/08/19/php-bug/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="php升级碰到的坑"><a href="#php升级碰到的坑" class="headerlink" title="php升级碰到的坑"></a>php升级碰到的坑</h2><blockquote>
<p>某天重新编译了PHP，然后就有了这篇文章. 大写的坑</p>
</blockquote>
<ol>
<li>未拷贝新编译php到/etc/bin/php，使得服务器读到的还是老版本然后使用<code>composer</code>去更新插件的时候老报环境错误,然后调试了<code>phpinfo()</code>环境是对的,一头雾水找不到问题。</li>
<li>新的<code>php.ini</code>错误提示(<code>display_errors</code>)未开启,然后就呵呵了,写入<code>session</code>的时候一直没看到错误,然后一直折腾一直折腾,最后开启了错误,看到了问题才发现服务器空间满了,空间满了,满了 ~_~</li>
</ol>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2016/08/16/php-mysql-data/" itemprop="url">
                  php mysql数据字典工具
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-16T19:38:39+08:00" content="2016-08-16">
              2016-08-16
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/08/16/php-mysql-data/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/08/16/php-mysql-data/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>不废话，直接上代码</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">/**</span><br><span class="line"> * 生成mysql数据字典</span><br><span class="line"> */</span><br><span class="line">header(&quot;Content-type: text/html; charset=utf-8&quot;);</span><br><span class="line">//配置数据库</span><br><span class="line">$dbserver   = &quot;localhost&quot;;</span><br><span class="line">$dbusername = &quot;dbUserName&quot;;</span><br><span class="line">$dbpassword = &quot;dbPWD&quot;;</span><br><span class="line">$database   = &quot;dbName&quot;;</span><br><span class="line"></span><br><span class="line">//其他配置</span><br><span class="line">$mysql_conn = @mysql_connect(&quot;$dbserver&quot;, &quot;$dbusername&quot;, &quot;$dbpassword&quot;) or die(&quot;Mysql connect is error.&quot;);</span><br><span class="line">mysql_select_db($database, $mysql_conn);</span><br><span class="line">mysql_query(&apos;SET NAMES utf8&apos;, $mysql_conn);</span><br><span class="line">$table_result = mysql_query(&apos;show tables&apos;, $mysql_conn);</span><br><span class="line"></span><br><span class="line">$no_show_table = array();    //不需要显示的表</span><br><span class="line">$no_show_field = array();   //不需要显示的字段</span><br><span class="line"></span><br><span class="line">//取得所有的表名</span><br><span class="line">while($row = mysql_fetch_array($table_result))&#123;</span><br><span class="line">	if(!in_array($row[0],$no_show_table))&#123;</span><br><span class="line">		$tables[][&apos;TABLE_NAME&apos;] = $row[0];</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line">//替换所以表的表前缀</span><br><span class="line">if(@$_GET[&apos;prefix&apos;])&#123;</span><br><span class="line">	die;</span><br><span class="line">	$prefix = &apos;czzj&apos;;</span><br><span class="line">	foreach($tables as $key =&gt; $val)&#123;</span><br><span class="line">		$tableName = $val[&apos;TABLE_NAME&apos;];</span><br><span class="line">		$string = explode(&apos;_&apos;,$tableName);</span><br><span class="line">		if($string[0] != $prefix)&#123;  </span><br><span class="line">			$string[0] = $prefix;  </span><br><span class="line">			$newTableName = implode(&apos;_&apos;, $string);  </span><br><span class="line">			mysql_query(&apos;rename table &apos;.$tableName.&apos; TO &apos;.$newTableName);  </span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	echo &quot;替换成功！&quot;;exit();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//循环取得所有表的备注及表中列消息</span><br><span class="line">foreach ($tables as $k=&gt;$v) &#123;</span><br><span class="line">    $sql  = &apos;SELECT * FROM &apos;;</span><br><span class="line">    $sql .= &apos;INFORMATION_SCHEMA.TABLES &apos;;</span><br><span class="line">    $sql .= &apos;WHERE &apos;;</span><br><span class="line">    $sql .= &quot;table_name = &apos;&#123;$v[&apos;TABLE_NAME&apos;]&#125;&apos;  AND table_schema = &apos;&#123;$database&#125;&apos;&quot;;</span><br><span class="line">    $table_result = mysql_query($sql, $mysql_conn);</span><br><span class="line">    while ($t = mysql_fetch_array($table_result) ) &#123;</span><br><span class="line">        $tables[$k][&apos;TABLE_COMMENT&apos;] = $t[&apos;TABLE_COMMENT&apos;];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $sql  = &apos;SELECT * FROM &apos;;</span><br><span class="line">    $sql .= &apos;INFORMATION_SCHEMA.COLUMNS &apos;;</span><br><span class="line">    $sql .= &apos;WHERE &apos;;</span><br><span class="line">    $sql .= &quot;table_name = &apos;&#123;$v[&apos;TABLE_NAME&apos;]&#125;&apos; AND table_schema = &apos;&#123;$database&#125;&apos;&quot;;</span><br><span class="line"></span><br><span class="line">    $fields = array();</span><br><span class="line">    $field_result = mysql_query($sql, $mysql_conn);</span><br><span class="line">    while ($t = mysql_fetch_array($field_result) ) &#123;</span><br><span class="line">        $fields[] = $t;</span><br><span class="line">    &#125;</span><br><span class="line">    $tables[$k][&apos;COLUMN&apos;] = $fields;</span><br><span class="line">&#125;</span><br><span class="line">mysql_close($mysql_conn);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">$html = &apos;&apos;;</span><br><span class="line">//循环所有表</span><br><span class="line">foreach ($tables as $k=&gt;$v) &#123;</span><br><span class="line">    $html .= &apos;	&lt;h3&gt;&apos; . ($k + 1) . &apos;、&apos; . $v[&apos;TABLE_COMMENT&apos;] .&apos;  （&apos;. $v[&apos;TABLE_NAME&apos;]. &apos;）&lt;/h3&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">    $html .= &apos;	&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot;&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">    $html .= &apos;		&lt;tbody&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;			&lt;tr&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;字段名&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;数据类型&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;默认值&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;允许非空&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;自动递增&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;				&lt;th&gt;备注&lt;/th&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;			&lt;/tr&gt;&apos;.&quot;\n&quot;;</span><br><span class="line"></span><br><span class="line">    foreach ($v[&apos;COLUMN&apos;] as $f) &#123;</span><br><span class="line">		if(@!is_array($no_show_field[$v[&apos;TABLE_NAME&apos;]]))&#123;</span><br><span class="line">			$no_show_field[$v[&apos;TABLE_NAME&apos;]] = array();</span><br><span class="line">		&#125;</span><br><span class="line">		if(!in_array($f[&apos;COLUMN_NAME&apos;],$no_show_field[$v[&apos;TABLE_NAME&apos;]]))&#123;</span><br><span class="line">			$html .= &apos;			&lt;tr&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c1&quot;&gt;&apos; . $f[&apos;COLUMN_NAME&apos;] . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c2&quot;&gt;&apos; . $f[&apos;COLUMN_TYPE&apos;] . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c3&quot;&gt;&apos; . $f[&apos;COLUMN_DEFAULT&apos;] . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c4&quot;&gt;&apos; . $f[&apos;IS_NULLABLE&apos;] . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c5&quot;&gt;&apos; . ($f[&apos;EXTRA&apos;]==&apos;auto_increment&apos;?&apos;是&apos;:&apos;&amp;nbsp;&apos;) . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;				&lt;td class=&quot;c6&quot;&gt;&apos; . $f[&apos;COLUMN_COMMENT&apos;] . &apos;&lt;/td&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">			$html .= &apos;			&lt;/tr&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">		&#125;</span><br><span class="line">    &#125;</span><br><span class="line">    $html .= &apos;		&lt;/tbody&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">	$html .= &apos;	&lt;/table&gt;&apos;.&quot;\n&quot;;</span><br><span class="line">&#125;</span><br><span class="line">?&gt;</span><br><span class="line">&lt;!doctype html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta charset=&quot;utf-8&quot;&gt;</span><br><span class="line">&lt;title&gt;数据库数据字典生成代码&lt;/title&gt;</span><br><span class="line">&lt;meta name=&quot;generator&quot; content=&quot;ThinkDb V1.0&quot; /&gt;</span><br><span class="line">&lt;meta name=&quot;author&quot; content=&quot;南昌腾速科技有限公司http://www.tensent.cn&quot; /&gt;</span><br><span class="line">&lt;meta name=&quot;copyright&quot; content=&quot;2008-2014 Tensent Inc.&quot; /&gt;</span><br><span class="line">&lt;style&gt;</span><br><span class="line">body, td, th &#123; font-family: &quot;微软雅黑&quot;; font-size: 14px; &#125;</span><br><span class="line">.warp&#123;margin:auto; width:900px;&#125;</span><br><span class="line">.warp h3&#123;margin:0px; padding:0px; line-height:30px; margin-top:10px;&#125;</span><br><span class="line">table &#123; border-collapse: collapse; border: 1px solid #CCC; background: #efefef; &#125;</span><br><span class="line">table th &#123; text-align: left; font-weight: bold; height: 26px; line-height: 26px; font-size: 14px; text-align:center; border: 1px solid #CCC; padding:5px;&#125;</span><br><span class="line">table td &#123; height: 20px; font-size: 14px; border: 1px solid #CCC; background-color: #fff; padding:5px;&#125;</span><br><span class="line">.c1 &#123; width: 120px; &#125;</span><br><span class="line">.c2 &#123; width: 120px; &#125;</span><br><span class="line">.c3 &#123; width: 150px; &#125;</span><br><span class="line">.c4 &#123; width: 80px; text-align:center;&#125;</span><br><span class="line">.c5 &#123; width: 80px; text-align:center;&#125;</span><br><span class="line">.c6 &#123; width: 270px; &#125;</span><br><span class="line">&lt;/style&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div class=&quot;warp&quot;&gt;</span><br><span class="line">	&lt;h1 style=&quot;text-align:center;&quot;&gt;数据库数据字典生成代码&lt;/h1&gt;</span><br><span class="line">&lt;?php echo $html; ?&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2016/06/16/php-cURL-does-not-see-hosts/" itemprop="url">
                  php cURL跳过了本地的hosts
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-06-16T14:48:44+08:00" content="2016-06-16">
              2016-06-16
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/06/16/php-cURL-does-not-see-hosts/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/06/16/php-cURL-does-not-see-hosts/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>需要跑一个脚本插入数据,用<code>cURL</code>方式,本地配置了虚拟主机映射了域名。没想到<code>cURL</code>居然没走<code>hosts</code>直接穿透出去了,我本地<code>hosts</code>配置<code>127.0.0.1 www.example.dev</code></p>
</blockquote>
<hr>
<h3 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h3><p>请求的<code>URL</code>不能写映射的域名，需要些本机的<code>IP</code>，然后你还需要加一个<code>header</code>头<code>Host: www.example.dev</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">$header = array</span><br><span class="line">(</span><br><span class="line">    &quot;Host: www.example.dev&quot;, // IMPORTANT</span><br><span class="line">    &quot;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;,</span><br><span class="line">    &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3&quot;,</span><br><span class="line">    &quot;Accept-Encoding: gzip,deflate,sdch&quot;,</span><br><span class="line">    &quot;Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4&quot;,</span><br><span class="line">    &quot;Cache-Control: max-age=0&quot;,</span><br><span class="line">    &quot;Connection: keep-alive&quot;,</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">curl_setopt($this-&gt;ch, CURLOPT_URL, &apos;http://127.0.1/&apos;);</span><br><span class="line">curl_setopt($this-&gt;ch, CURLOPT_HTTPHEADER, $header);</span><br></pre></td></tr></table></figure>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://7xnghc.com1.z0.glb.clouddn.com/logo.jpg"
               alt="项羽大大" />
          <p class="site-author-name" itemprop="name">项羽大大</p>
          <p class="site-description motion-element" itemprop="description">敲敲代码看看电视刷刷微博</p>

        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">9</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">8</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/fengci" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/1924817755" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.mrwood.xyz/" title="KIWI的小屋" target="_blank">KIWI的小屋</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://xpal7512.github.io/" title="方寸随心" target="_blank">方寸随心</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">项羽大大</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"fengci"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  

</body>
</html>
